package com.dfrz.config;

import com.dfrz.entity.Result;

import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author 29877
 */ //全局异常处理器
@RestControllerAdvice
public class GlobalExceptionHandler {

    //所有的运行时异常都从此方法抛出
    @ExceptionHandler(RuntimeException.class)
    public Result<RuntimeException> abnormalEx(RuntimeException ex){
        ex.printStackTrace();
        return Result.exception(500,ex.getMessage());
    }

    //所有的自定义异常都从此方法抛出
    @ExceptionHandler(CustomException.class)
    public Result<CustomException> customAbnormalEx(CustomException ex){
        ex.printStackTrace();
        return Result.exception(ex.getCode(),ex.getMessage());
    }
}
